<?php
$dt = new DataTable(constant('DB_TABLE_FLOAT_WINDOW_AD'));
$GLOBALS['GV_IMAGE_PATH'] = 'float_window_ad/';
if ( isset($_REQUEST['act']) && $_REQUEST['act'] == 'del' ) {
	$row = $dt->get(intVal($_REQUEST['id']));
	if ( $row['img'] ) {
		$GLOBALS['APP_INSTANCE']->removeFile($row['img'], $GLOBALS['GV_IMAGE_PATH']);
	}
	$dt->remove($row['id']);
	ob_clean();
	header('Location:mainc.php');
}
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$info = $_POST;
$img_key = isset($info[$dt->getPrimaryKey()]) && intVal($info[$dt->getPrimaryKey()]) > 0?'ajaxf_hot_good_'.$info[$dt->getPrimaryKey()]:'ajaxf_hot_good_new';
if ( strlen($info[$img_key]) > 0) {
	$GLOBALS['APP_INSTANCE']->saveUploadedFile($info[$img_key], $GLOBALS['GV_IMAGE_PATH'] );
	$info['img'] = $info[$img_key];
	#delete exist image on disk
	$row = $dt->get(intVal($info['id']));
	if ( $row['img'] ) {
		$GLOBALS['APP_INSTANCE']->removeFile($row['img'], $GLOBALS['GV_IMAGE_PATH']);
	}
}
$dt->save($info);
}
$GLOBALS['list_data'] = $dt->get_list('','order');
?>